<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">景区管理 <small>机器列表 </small></h3>
            <?php echo breadcrumb(array('景区管理', '景区产品', '机器列表'));?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-search"></i>搜索</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal form-search" action="<?php echo base_url('macs/grid') ?>" method="get">
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">机器搜索</label>
                                    <div class="controls">
                                         <input type="text" name="mac_search" value="<?php echo $this->input->get('mac_search');?>" class="m-wrap span12" placeholder="请输入机器编号或机器名称">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">景区编号</label>
                                    <div class="controls">
                                         <input type="text" name="sid" value="<?php echo $this->input->get('sid');?>" class="m-wrap span12" placeholder="请输入景区编号">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">检票帐号</label>
                                    <div class="controls">
                                         <input type="text" name="teller_name" value="<?php echo $this->input->get('teller_name');?>" class="m-wrap span12" placeholder="请输入检票帐号或别名">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">机器状态</label>
                                    <div class="controls">
                                        <select name="isfree" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <option value="Y" <?php if ($this->input->get('isfree') == 'Y') :?> selected="selected"<?php endif;?>>冻结</option>
                                            <option value="N" <?php if ($this->input->get('isfree') == 'N') :?> selected="selected"<?php endif;?>>正常</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit">搜索</button>
                            <button class="btn reset_button_search" type="button">重置条件</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>列表</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="dataTables_wrapper form-inline">
                        <div class="clearfix">
                            <a href="<?php echo base_url('macs/add') ?>" class="add-button-link">
                                <div class="btn-group">
                                    <button class="btn green"><i class="icon-plus"></i> 添加</button>
                                </div>
                            </a>
                        </div>
                        <?php if ($page_list->num_rows() > 0) :?>
                        <table class="table table-striped table-bordered table-hover" id="sample_1">
                            <thead class="flip-content">
                                <tr>
                                    <th><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"></th>
                                    <th>机器编号</th>
                                    <th>机器名称（景区编号）</th>
                                    <th>检票帐号（机器对应）</th>
                                    <th>特殊订单</th>
                                    <th>订单序号</th>
                                    <th>通讯日期</th>
                                    <th>运行状态</th>
                                    <th>使用状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($page_list->result() as $item) : ?>
                                <tr>
                                    <td width="20"><input type="checkbox" class="checkboxes" value="1" ></td>
                                    <td width="70"><?php echo $item->mac_id ;?></td>
                                    <td><?php echo $item->mac_name;?>（<?php echo $item->sid;?>）</td>
                                    <td>
                                        <p><?php echo $item->user_name;?>（<?php echo $item->teller_uid;?>）</p>
                                        <p><?php echo $item->alias_name;?></p>
                                    </td>
                                    <td><?php echo $item->special_id;?></td>
                                    <td><?php echo $item->order_id;?></td>
                                    <td><?php echo date('Y-m-d H:i:s',$item->act_time);?></td>
                                    <td><img src="<?php echo (time()-($item->act_time))<=60*30?'skins/admin/images/mac_online.gif':'skins/admin/images/mac_offline_static.gif';?>"/></td>
                                    <td>
                                        <a href="javascript:;" class="freeze glyphicons no-js <?php if ($item->isfree =='N'):?>ok_2<?php else :?>remove_2<?php endif;?>" mac_id="<?php echo $item->mac_id ;?>">
                                            <i></i>
                                        </a>
                                    </td>
                                    <td width="125">
                                        <a class="btn mini green" href="<?php echo base_url('macs/edit/'.$item->mac_id);?>">编辑</a>
                                        <a class="btn mini green" href="<?php echo base_url('macs/orderSend/'.$item->mac_id);?>">推送</a>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            </tbody>
                        </table>
                        <div class="row-fluid">
                            <div class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now?></span>页 
                                <span>共</span><span style="color: red"><?php echo $all_rows?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_link;?>
                            </div>
                        </div>
                        <?php else:?>
                            <div class="alert"><p>未找到数据。<p></div>
                        <?php endif;?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(document).ready(function(){
    $('.table-hover').on('click', '.freeze', function(){
    	var obj = $(this);
    	var name = (obj.hasClass('ok_2')) ? '冻结' : '解冻';
    	if (confirm('你确定要将该机器'+name+'吗？')) {
    		var url = location.origin+'/macs/doFree';
    		var mac_id = obj.attr('mac_id');
			var isfree = (obj.hasClass('ok_2')) ? 'Y' :'N';
			$.post(url, {mac_id:mac_id,isfree:isfree}, function(data){
				if(data.status){
					if (data.isfree == 'Y') {
                        obj.addClass('remove_2').removeClass('ok_2');
                    } else {
                        obj.addClass('ok_2').removeClass('remove_2');
                    }
				}
			}, 'json');
    	}
     });
});
</script>